package main

import (
	"fmt"
	"io/ioutil"
	"strconv"
)

type Search struct {
	RootPath    string
	Maxfilesize int64
	SizeUnit    int64
}

func (s Search) seaFile(mf *maxFiledAdmin) {
	file, err := ioutil.ReadDir(s.RootPath)
	if err != nil {
		fmt.Printf("文件读取失败！%v \n", err)
		return
	}

	for _, fil := range file {
		if fil.IsDir() {
			sr := Search{
				RootPath:    s.RootPath + "\\" + fil.Name(),
				Maxfilesize: s.Maxfilesize,
			}
			sr.seaFile(mf)
		} else {
			if fil.Size() > s.Maxfilesize {
				mf.adminFile = append(mf.adminFile, newMaxFile(s.RootPath+"\\"+fil.Name(), strconv.FormatInt(fil.Size()/MB, 10)+"MB"))
			}
		}
	}
}

func newSearch(rootPath string, maxfilesize, sizeUnit int64) Search {
	return Search{
		RootPath:    rootPath,
		Maxfilesize: maxfilesize,
		SizeUnit:    sizeUnit,
	}
}

// 大文件结构体
type maxFile struct {
	fielPath string
	fileSize string
}

func newMaxFile(filePath, fileSize string) maxFile {
	return maxFile{
		fielPath: filePath,
		fileSize: fileSize,
	}
}

// 创建文件管理的结构体
type maxFiledAdmin struct {
	adminFile []maxFile
}
